package com.min.redis.common.util;


import lombok.NoArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;

/**
 * @author wangmin
 * @date 2023/12/31
 */
@NoArgsConstructor
public class LogUtils {
    public static final Logger COMMON = LoggerFactory.getLogger("common");
    public static final Logger WARN = LoggerFactory.getLogger("warn");
    public static final Logger ERROR = LoggerFactory.getLogger("error");

    /**
     * message formatter,format like "aa:{},bb:{}"
     *
     * @param format
     * @param args
     * @return
     */
    public static String messageFormatter(String format, Object... args) {
        return messageArrayFormatter(format, args);
    }

    /**
     * message formatter,format like "aa:{},bb:{}"
     * @param format
     * @param args
     * @return
     */
    public static String messageArrayFormatter(String format, Object[] args) {
        String message = format;
        if (args != null && args.length > 0) {
            FormattingTuple formatted = MessageFormatter.arrayFormat(format, args);
            message = formatted.getMessage();
        }
        return message;
    }
}